<?php
namespace app\admin\controller;
use think\console\Input;

use think\Request;

use think\Controller;
use think\Db;
class Right extends Controller
{
public function right()
   {
   	$list=Db::name("jf_students")
   	        ->paginate(2);
            
            $page = $list->render();

            $this->assign('list',$list);
            $this->assign('page', $page);
      return $this->fetch();

   }
   public function add()
   {
   	  $request=Request::instance();
   	  if($request->has('sub','post'))
   	  {
   	     $s_number=$request->post('s_number');
   	     $s_name=$request->post('s_name');
   	     $s_sex=$request->post('s_sex');
   	     $s_age=$request->post('s_age');
   	     $s_nation=$request->post('s_nation');
   	     $s_place=$request->post('s_place');
   	     $s_pwd=$request->post('s_pwd');
   	     $data=[
   	           's_number'=>$s_number,
   	           's_name'=>$s_name,
   	           's_sex'=>$s_sex,
   	           's_age'=>$s_age,
	   	       's_nation'=>$s_nation,
	   	       's_place'=>$s_place,
	   	       's_pwd'=>$s_pwd,	   	           
   	     ];
   	   $result=Db::table('jf_students')->insert($data);
   	   if($result)
   	   {
   	      $this->success('新增成功','Right/right');
   	   }
   	   else 
   	   {
   	      $this->error('新增失败');
   	   }
   	  }
   	  else 
   	  {
   	     $s_id=input('?param.s_id');
   	     $jf_students=Db::table('jf_students')->where('s_id',$s_id)->find();
   	     return $this->fetch('add',[
   	                             'jf_students'=>$jf_students
   	         ]);
   	  }
      //return $this->fetch(); 
   }
   public function update()
   {
    /* if (input('?param.sub'))
     {
       $data=[
               's_id'=>input("post.s_id")
               "s_number"=>input("post.s_number"),
   	           's_name'=>input("post.s_name"),
   	           's_sex'=>input("post.s_sex"),
   	           's_age'=>input("post.s_age"),
	   	       's_nation'=>input("post.s_nation"),
	   	       's_place'=>input("post.s_place"),
	   	       's_pwd'=>input("post.s_pwd"),	 
       ];
       $result=Db::table("jf_students")->update($data);
       if($result)
       {
       	$this->success('修改成功','Right/update');
       }
       else 
       {
         $this->error('修改失败');
       }
     }
     else 
     {
        $s_id=input('?param.s_id');
   	     $jf_students=Db::table('jf_students')->where('s_id',$s_id)->find();
   	     return $this->fetch('update',[
   	                             'jf_students'=>$jf_students,
   	         ]); 
     }*/
   	$request=Request::instance();
  	if ($request->has("sub","post"))
  	{
	     $s_id=$request->param("s_id");
	     $s_number=$request->post('s_number');
   	     $s_name=$request->post('s_name');
   	     $s_sex=$request->post('s_sex');
   	     $s_age=$request->post('s_age');
   	     $s_nation=$request->post('s_nation');
   	     $s_place=$request->post('s_place');
   	     $s_pwd=$request->post('s_pwd');
	  	 $data=[
	  	       's_id'=>$s_id,
   	           's_number'=>$s_number,
   	           's_name'=>$s_name,
   	           's_sex'=>$s_sex,
   	           's_age'=>$s_age,
	   	       's_nation'=>$s_nation,
	   	       's_place'=>$s_place,
	   	       's_pwd'=>$s_pwd,	   	           
   	      ]; 	  	    
	     $result=Db::table("jf_students")
		         ->update($data);
	  	if($result)
		  {$this->success("修改成功","Right/right");}
	    else 
		  {$this->error("修改失败");}
	  	}
  	else 
  	{
	  	$s_id=$request->param("s_id");
	  	$data=['s_id'=>$s_id];  
		$list=Db::name("jf_students")
			  ->where('s_id',$s_id)
	          ->find();
	     return $this->fetch('update',[
               'list'=>$list,
       ]);        
  	}
   }
   public function duoshan(){
     if(input("?post.sub"))
		{
		   $request=Request::instance();
		   $checkbox=[];
		   if($checkbox==false)
		   {
		     $this->redirect("Right/right");
		     
		   }
		   else 
		   {		     
		   
	       $checkbox=$_POST['checkbox'];//接受id值
			foreach($checkbox as $value)
			{
				$result=Db::table('jf_students')->where('s_id',$value)->delete();
			}

            if($result)
            {
                $this->success("删除成功","Right/right");
            }
            else
            {
                $this->error("删除失败");
            }
		}
	  }
   }
   
   public function delete()
   {
      $request=Request::instance();
      $s_id=$request->param('s_id');
      $data=['s_id'=>$s_id];
      $result=Db::table('jf_students')->delete($data);
       if($result)
      {
        $this->success('删除成功','Right/right');  
      }
      else 
      {
        $this->error('删除失败');
      }
      
   }
}